namespace ClassyBlog.Infrastructure
{
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.Mvc;

    // Copied from ASP.NET MVC Source, only changed the base type
    [DebuggerNonUserCode, CompilerGenerated]
    public abstract class DefaultWebViewPage<TModel> : DefaultWebViewPage
    {
        private ViewDataDictionary<TModel> localViewData;

        public new AjaxHelper<TModel> Ajax { get; set; }

        public new HtmlHelper<TModel> Html { get; set; }

        public new TModel Model
        {
            get { return ViewData.Model; }
        }

        public new ViewDataDictionary<TModel> ViewData
        {
            get
            {
                if (localViewData == null)
                {
                    SetViewData(new ViewDataDictionary<TModel>());
                }

                return localViewData;
            }

            set
            {
                SetViewData(value);
            }
        }

        public override void InitHelpers()
        {
            base.InitHelpers();

            Ajax = new AjaxHelper<TModel>(ViewContext, this);
            Html = new HtmlHelper<TModel>(ViewContext, this);
        }

        protected override void SetViewData(ViewDataDictionary viewData)
        {
            localViewData = new ViewDataDictionary<TModel>(viewData);

            base.SetViewData(localViewData);
        }
    }
}